﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using LinQ_DTO;
namespace DAO
{
    public class SanPhamThietKeDAO
    {
        public List<shop_sanphamthietke> LayTatCaSanPhamThietKe()
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var products = from a in EFashionDB.shop_sanphamthietkes select a;
            return products.ToList();
        }
        public int ThemSanPhamThietKe(shop_sanphamthietke AddObject)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            EFashionDB.shop_sanphamthietkes.InsertOnSubmit(AddObject);
            EFashionDB.SubmitChanges();
            return AddObject.MaSanPhamThietKe;
        }
        public void XoaSanPhamThietKe(int Ma)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListResultQuery = from a in EFashionDB.shop_sanphamthietkes
                                  where a.MaSanPhamThietKe == Ma
                                  select a;
            if (ListResultQuery.Count() > 0)
            {
                shop_sanphamthietke Result = ListResultQuery.Single();
                EFashionDB.shop_sanphamthietkes.DeleteOnSubmit(Result);
                EFashionDB.SubmitChanges();
            }
        }
        public void CapNhatSanPhamThietKe(int Ma, shop_sanphamthietke EditObject)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var ListResultQuery = from a in EFashionDB.shop_sanphamthietkes
                                  where a.MaSanPhamThietKe == Ma
                                  select a;
            if (ListResultQuery.Count() > 0)
            {
                shop_sanphamthietke Result = ListResultQuery.Single();

                Result.ChiTiet = EditObject.ChiTiet;
                Result.MaNguoiDung = EditObject.MaNguoiDung;
                Result.MaSanPhamGoc = EditObject.MaSanPhamGoc;
                Result.NgayThietKe = EditObject.NgayThietKe;
                EFashionDB.SubmitChanges();
            }
        }
        public List<shop_sanphamthietke> LaySanPhamThietKeTheoMaNguoiDung(Guid MaNguoiDung)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var products = from a in EFashionDB.shop_sanphamthietkes 
                           where a.MaNguoiDung == MaNguoiDung
                           select a;
            return products.ToList();
        }
        public shop_sanphamthietke LaySanPhamThietKeTheoMaSanPham(int MaSanPham)
        {
            EFashionDBDataContext EFashionDB = new EFashionDBDataContext();
            var products = from a in EFashionDB.shop_sanphamthietkes
                           where a.MaSanPhamThietKe == MaSanPham
                           select a;
            shop_sanphamthietke sp = products.Single();
            return sp;
        }
    }
}
